package com.elitesland.demo.controller.backend.tms;

import com.elitesland.b2c.tms.service.TmsFareTmplService;
import com.elitesland.b2c.tms.vo.param.TmsFareTmplPageParamVO;
import com.elitesland.b2c.tms.vo.resp.TmsFareTmplDetailRespVO;
import com.elitesland.b2c.tms.vo.resp.TmsFareTmplPageRespVO;
import com.elitesland.b2c.tms.vo.save.TmsFareTmplSaveVO;
import com.elitesland.core.base.ApiResult;
import com.elitesland.core.base.PagingVO;
import com.elitesland.demo.controller.BaseController;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * .
 *
 * @author Kaiser（wang shao）
 * @date 2021-02-09
 */
@Api(tags = "运费模板管理")
@ApiSupport(author = "wang shao", order = 11)
@RestController
@RequestMapping(value = "/tms/fareTmpl", produces = MediaType.APPLICATION_JSON_VALUE)
public class TmsFareTmplController extends BaseController {

    @Autowired
    private TmsFareTmplService tmsFareTmplService;

    @ApiOperation("新增模板")
    @ApiOperationSupport(order = 1)
    @PostMapping("")
    public ApiResult<Long> save(@RequestBody TmsFareTmplSaveVO saveVO) {
        return tmsFareTmplService.save(saveVO);
    }

    @ApiOperation("修改模板")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模板ID", required = true)
    })
    @PutMapping("/{id}")
    public ApiResult<Long> update(@PathVariable Long id, @RequestBody TmsFareTmplSaveVO saveVO) {
        return tmsFareTmplService.update(id, saveVO);
    }

    @ApiOperation("获取模板详情")
    @ApiOperationSupport(order = 3)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模板ID", required = true)
    })
    @GetMapping("/{id}")
    public ApiResult<TmsFareTmplDetailRespVO> get(@PathVariable Long id) {
        return tmsFareTmplService.get(id);
    }

    @ApiOperation("删除模板数据")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模板ID", required = true)
    })
    @DeleteMapping("/{id}")
    public ApiResult<Long> delete(@PathVariable Long id) {
        return tmsFareTmplService.delete(id);
    }

    @ApiOperation("批量删除模板数据")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "模板ID", required = true, allowMultiple = true)
    })
    @DeleteMapping("/delete")
    public ApiResult<List<Long>> deleteBatch(@RequestBody List<Long> ids) {
        return tmsFareTmplService.delete(ids);
    }

    @ApiOperation("分页查询模板数据")
    @ApiOperationSupport(order = 5)
    @PostMapping("/search")
    public ApiResult<PagingVO<TmsFareTmplPageRespVO>> search(@RequestBody TmsFareTmplPageParamVO pageParamVO) {
        return tmsFareTmplService.search(pageParamVO);
    }

    @ApiOperation("切换启用状态")
    @ApiOperationSupport(order = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "模板ID", required = true)
    })
    @PatchMapping("/{id}/enabled")
    public ApiResult<Long> updateEnable(@PathVariable Long id) {
        return tmsFareTmplService.updateEnable(id);
    }

    @ApiOperation("批量启用或禁用")
    @ApiOperationSupport(order = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "模板ID", required = true, allowMultiple = true),
            @ApiImplicitParam(name = "enabled", value = "是否启用", required = true)
    })
    @PatchMapping("/enabled/{enabled}")
    public ApiResult<List<Long>> updateEnableBatch(@RequestBody List<Long> ids, @PathVariable Boolean enabled) {
        return tmsFareTmplService.updateEnable(ids, enabled);
    }
}
